'use strict';

const { strict } = require("assert");

const db = uniCloud.database();

exports.main = async (event, context) => {
	try {
		const collection = db.collection('popup_config');
		const res = await collection.where({
			article_status:1 // 使用正确的status字段查询启用状态
		}).orderBy('publish_date', 'desc').field({
			title: true,
			content: true,
			article_status:true
		}).get();

		console.log('查询结果:', res);

		if (!res.data || res.data.length === 0) {
			console.warn('没有找到状态为启用的公告数据');
		}

		return {
			code: 0,
			msg: '获取成功',
			data: res.data
		};
	} catch (e) {
		return {
			code: -1,
			msg: '获取失败：' + e.message
		};
	}
};